#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021-6-27 14:11
# @Author  : ling
# @File    : TestContact.py
# @Software: PyCharm

from time import sleep

import pytest
import yaml
from appium.webdriver.common.mobileby import MobileBy


from python_app_outo.com.app.base.base import Base


# 获取测试用例数据
def get_datas():
    with open('test_contact_data.yaml',encoding='UTF-8' ) as f:
        datas = yaml.safe_load(f)
        # 获取add数据
        addContact_fail = datas['addContact_fail']
        addContact_successe = datas['addContact_successe']


    return [addContact_fail,addContact_successe]


class TestAddContact(Base):



    @pytest.mark.parametrize("name, phoneNum, expected", get_datas()[0])
    def test_add_fail(self, name, phoneNum, expected):
        print(f"姓名{name},手机号:{phoneNum}预期结果:{expected}")
        """"
        前提条件：登陆状态  caps["noReset"] = "true"
        1、点击通讯录
        2、点击添加成员
        3、点击添加手动输入链接，跳转到添加成员页面
        5、输入姓名、手机号、点击保存
        6、断言判断
        """

        self.driver.find_element(MobileBy.XPATH, "//*[@text='通讯录']").click()
        self.driver.find_element(MobileBy.XPATH, "//*[@text='添加成员']").click()
        self.driver.find_element(MobileBy.XPATH, "//*[@text='手动输入添加']").click()
        self.driver.find_element(MobileBy.XPATH,
                                 "//*[contains(@text, '姓名')]/../android.widget.EditText").send_keys(name)
        self.driver.find_element(MobileBy.XPATH, "//*[contains(@text, '手机')]/..//*[@text='必填']").send_keys(phoneNum)
        self.driver.find_element(MobileBy.XPATH, "//*[@text='保存']").click()


        result=self.driver.find_element(MobileBy.ID, "com.tencent.wework:id/bg4").get_attribute("text")
        print(f"a====={result}")

        # 断言
        assert result==expected

    @pytest.mark.parametrize("name, phoneNum, expected", get_datas()[1])
    def test_add_successe(self, name, phoneNum, expected):
        print(f"姓名{name},手机号:{phoneNum}预期结果:{expected}")
        """"
        前提条件：登陆状态  caps["noReset"] = "true"
        1、点击通讯录
        2、点击添加成员
        3、点击添加手动输入链接，跳转到添加成员页面
        5、输入姓名、手机号、点击保存
        6、断言判断
        """

        self.driver.find_element(MobileBy.XPATH, "//*[@text='通讯录']").click()
        self.driver.find_element(MobileBy.XPATH, "//*[@text='添加成员']").click()
        self.driver.find_element(MobileBy.XPATH, "//*[@text='手动输入添加']").click()
        self.driver.find_element(MobileBy.XPATH,
                                 "//*[contains(@text, '姓名')]/../android.widget.EditText").send_keys(name)
        self.driver.find_element(MobileBy.XPATH, "//*[contains(@text, '手机')]/..//*[@text='必填']").send_keys(phoneNum)
        self.driver.find_element(MobileBy.XPATH, "//*[@text='保存']").click()

        result = self.driver.find_element(MobileBy.XPATH, "//*[@class='android.widget.Toast']").get_attribute("text")
        print(f"a====={result}")

        # 断言
        assert result == expected

